﻿
@{
    Layout = null;
}
<div class="bjui-pageContent">
    <table class="table table-bordered" id="datagrid-Menu@(Request.QueryString["_"])" data-toggle="datagrid"></table>
</div>
<script type="text/javascript">
    var menuGrid@(Request.QueryString["_"]) = $('#datagrid-Menu@(Request.QueryString["_"])');
    menuGrid@(Request.QueryString["_"]).datagrid({
        width: '100%',
        height: '100%',
        showToolbar: true,
        toolbarItem: 'refresh,save,cancel',
        local: 'local',
        dataUrl: '/Menu/GetMenuTree',
        inlineEditMult: false,
        afterSave: saveCallBack,
        editUrl: '/Menu/MenuUpsert',
        delUrl: '/Menu/DelMenu',
        delPK: 'id',
        isTree: 'name',
        addLocation: 'last',
        showCheckboxcol: false,
        filterMult: false,
        filterThead: true,
        fieldSortable: false,
        toolbarCustom: customtBtn,
        columnMenu: false,
        paging: false,
        treeOptions: {
            expandAll: false,
            add: true,
            simpleData: true,
            keys: {
                parentKey: 'pid'
            }
        },
        columns: [
            { label: '@Html.CurLang("操作")', align: 'center', width: 300, render: datagrid_tree_operation },
            { name: 'name', align: 'center', width: 450, label: '@Html.CurLang("汉语菜单项")', rule: 'required' },
            { name: 'enname', align: 'center', width: 350, label: '@Html.CurLang("英语菜单项")' },
            //{ name: 'jpname', align: 'center', width: 350, label: '@Html.CurLang("日语菜单项")' },
            //{ name: 'korname', align: 'center', width: 350, label: '@Html.CurLang("韩语菜单项")' },
                    { name: 'spaname', align: 'center', width: 350, label: '@Html.CurLang("西班牙语菜单项")' },
            { name: 'id', align: 'center', width: 250, label: '@Html.CurLang("ID")' },
            { name: 'icon', align: 'center', width: 350, label: '@Html.CurLang("图标")' },
            { name: 'url', align: 'left', width: 350, label: '@Html.CurLang("url")' },
            {
                            name: 'pid', align: 'center', width: 250, label: '@Html.CurLang("父ID")', rule: 'required'//, attrs: { readonly: "readonly" }
            },
            { name: 'enabled', align: 'center', width: 150, label: '@Html.CurLang("是否禁用")', rule: 'required', type: 'select', items: [{ '1': '@Html.CurLang("启用")' }, { '0': '@Html.CurLang("禁用")' }] },
            { name: 'score', align: 'center', width: 200, label: '@Html.CurLang("排序")', rule: 'required;integer' }            
        ]
    });


                    function datagrid_tree_operation() {
                        var html = '<button type="button" class="btn-green" data-toggle="edit.datagrid.tr">' + '@Html.CurLang("编辑")' + '</button>'
                            + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">' +'@Html.CurLang("删除")' + '</button>';
                        return html;
                    }

                    function fanyin@(Request.QueryString["_"])() {
                        BJUI.alertmsg('confirm', '@Html.CurLang("已经翻译的是否需要替换？")', {
                            okName: '@Html.CurLang("是")', cancelName: '@Html.CurLang("否")', okCall: function () {
                                fanyinReq@(Request.QueryString["_"])(true);
                            }, cancelCall: function () {
                                fanyinReq@(Request.QueryString["_"])(false);
                            }
                        });
                    }

                    function fanyinReq@(Request.QueryString["_"])(isOK) {
                    $.ajax({
                        url: "/Lang/FanYin",
                        type: "POST",
                        data: { "type": "menu", "isReplace": isOK },
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (res)
                        {
                                if (res.Code === 1) {
                                    BJUI.alertmsg("ok", '@Html.CurLang("菜单名称已翻译完成！")', { alertTimeout: 2000 });
                                    setTimeout(refreshGri, 2000);
                                } else {
                                    BJUI.alertmsg('error', res.Msg);
                                }
                            },
                        error: function (xhr, status, errorThrown) {
                                BJUI.alertmsg('error', xhr.statusText);
                            }

                        });
                    }



                    function refreshGri() {
                        menuGrid@(Request.QueryString["_"]).datagrid('filter', {});
                    //menuGrid.datagrid('filter', { "clearOldPostData": true });
                }
                function customtBtn() {
                    return $("<button type='button' class='btn-default btn' onclick='fanyin@(Request.QueryString["_"])()'>" + '@Html.CurLang("实时翻译")' + "</button> <button type='button' class='btn-default btn' onclick='refreshGri()'>" + '@Html.CurLang("清空查询")' + "</button>");
            }

            function saveCallBack($trs, datas) {
                menuGrid@(Request.QueryString["_"]).datagrid('refresh', false);
            }


</script>
